<?php
	
	require_once("nusoap/nusoap.php");
	class CampaignSoap{
    	var $proxy;
        var $sess;
		
		var $totalRows;
		
        function CampaignSoap(){
		
			$this->proxy = $_SESSION["sugar_soap_proxy"];
			$this->sess = $_SESSION["sugar_session_id"];
			$this->recordCount = 0;
			
        }
				
				
		function getRows($query, $startIndex, $numberOfRows, $orderBy=' campaigns.date_modified desc', $includeDeleted){
		
			$recordCount = 0;
		
    		$result = $this->proxy->get_entry_list(
        		$this->sess,
        		'Campaigns',
        		$query,
        		$orderBy,
        		0,
        		array(
            		'id',
					'name',
					'date_entered',
            		'date_modified',
            		'modified_user_id',
					'created_by',
					'description',
					'assigned_user_id',
					'opportunity_type',
					'campaign_id',
            		'lead_source',
            		'amount',
					'amount_usdollar',
					'currency_id',
					'date_closed',
					'next_step',
					'sales_stage',
					'probability',
					'deleted'
        		),
        		0,
        		false
    		);
			
			$returnList = array();
			
			if ($result != "" && count($result) > 0) {
			
				foreach ($result['entry_list'] as $record) {
					$returnList[] = $record;
				}
			}
			
			if ($includeDeleted) {
				
			
				if ($deleteNumberOfRows != -1) {
					$deleteResult = $this->getDeletedRows($query, 0, 0, $orderBy);
					
					if ($deleteResult != "" && count($deleteResult) > 0) {
					
						foreach ($deleteResult['entry_list'] as $record) {
							$returnList[] = $record;
						}
					}
					
				}
			} 
			
			$this->recordCount = count($returnList);
			
			if ($numberOfRows > 0)
				$returnList = array_slice($returnList, $startIndex, $numberOfRows);
			
    		return $returnList;
		}
		
		function getTotalRows() {
		
			return $this->recordCount;
	
		}
		
		function getDeletedRows($query, $startIndex, $numberOfRows, $orderBy=' campaigns.date_modified desc'){
    		$result = $this->proxy->get_entry_list(
        		$this->sess,
        		'Campaigns',
        		$query,
        		$orderBy,
        		$startIndex,
        		array(
            		'id',
					'name',
					'date_entered',
            		'date_modified',
            		'modified_user_id',
					'created_by',
					'description',
					'assigned_user_id',
					'opportunity_type',
					'campaign_id',
            		'lead_source',
            		'amount',
					'amount_usdollar',
					'currency_id',
					'date_closed',
					'next_step',
					'sales_stage',
					'probability',
					'deleted'
        		),
        		$numberOfRows,
        		true
    		);
			
    		return $result;
		}
		
		
		function save($id, $name, $date_entered, $date_modified, $modified_user_id, $created_by,
					  $description, $assigned_user_id, $opportunity_type, $campaign_id,
            		  $lead_source, $amount, $amount_usdollar, $currency_id, $date_closed,
					  $next_step, $sales_stage, $probability) {
		
		
			if ($id) {
				$response = $this->proxy->set_entry($this->sess, 'Capaigns', 
								array(array("name" => 'id',"value" => $id),
									  array("name" => 'name',"value" => $photo_c),
									  array("name" => 'date_entered',"value" => $date_entered),
								      array("name" => 'date_modified',"value" => $date_modified),
            					      array("name" => 'modified_user_id',"value" => $modified_user_id),
									  array("name" => 'created_by',"value" => $created_by),
									  array("name" => 'description',"value" => $description),
									  array("name" => 'assigned_user_id',"value" => $assigned_user_id),
									  array("name" => 'opportunity_type',"value" => $opportunity_type),
									  array("name" => 'campaign_id',"value" => $campaign_id),
									  array("name" => 'lead_source',"value" => $lead_source),
									  array("name" => 'amount',"value" => $amount),
									  array("name" => 'amount_usdollar',"value" => $amount_usdollar),
									  array("name" => 'currency_id',"value" => $currency_id),
									  array("name" => 'date_closed',"value" => $date_closed),
									  array("name" => 'next_step',"value" => $next_step),
									  array("name" => 'sales_stage',"value" => $sales_stage),
									  array("name" => 'probability',"value" => $probability)
            						 )
            				);
			} else {
				$response = $this->proxy->set_entry($this->sess, 'Campaigns', 
								array(array("name" => 'name',"value" => $photo_c),
									  array("name" => 'date_entered',"value" => $date_entered),
								      array("name" => 'date_modified',"value" => $date_modified),
            					      array("name" => 'modified_user_id',"value" => $modified_user_id),
									  array("name" => 'created_by',"value" => $created_by),
									  array("name" => 'description',"value" => $description),
									  array("name" => 'assigned_user_id',"value" => $assigned_user_id),
									  array("name" => 'opportunity_type',"value" => $opportunity_type),
									  array("name" => 'campaign_id',"value" => $campaign_id),
									  array("name" => 'lead_source',"value" => $lead_source),
									  array("name" => 'amount',"value" => $amount),
									  array("name" => 'amount_usdollar',"value" => $amount_usdollar),
									  array("name" => 'currency_id',"value" => $currency_id),
									  array("name" => 'date_closed',"value" => $date_closed),
									  array("name" => 'next_step',"value" => $next_step),
									  array("name" => 'sales_stage',"value" => $sales_stage),
									  array("name" => 'probability',"value" => $probability)
									  )
            			);
            }				 
			return $response;
		}
		
		function delete($id) {
		
			$response = $this->proxy->set_entry($this->sess, 'Campaigns', 
								array(array("name" => 'id',"value" => $id),
									  array("name" => 'deleted',"value" => 1),
            						 )
            				);
		
			return $response;
		
		}
		
		function nameValuePairToSimpleArray($array){
    		$my_array=array();
    		while(list($name,$value)=each($array)){
        		$my_array[$value['name']]=$value['value'];
    		}
    		return $my_array;
		} 
		
		
	}
	
$campaignSoap = new CampaignSoap();
						  
$leadsArray = array("" => "",
				    "Cold Call" => "Cold Call",
					"Existing Customer" => "Existing Customer",
					"Self Generated" => "Self Generated",
					"Employee" => "Employee",
					"Partner" => "Partner",
					"Public Relations" => "Public Relations",
					"Direct Mail" => "Direct Mail",
					"Conference" => "Conference",
					"Trade Show" => "Trade Show",
					"Web Site" => "Web Site",
					"Word of mouth" => "Word of mouth",
					"Email" => "Email",
					"Campaign" => "Campaign",
					"Other" => "Other");
?>